import java.util.Arrays;

public class MyStack extends EmptyException{
    public int[] elem;
    public int usedSize;

    public MyStack() {

        this.elem = new int[10];
    }
    //进栈
    public void push(int val){
        if(isFull()){
            this.elem= Arrays.copyOf(elem,2*elem.length);
        }
        elem[usedSize++]=val;
    }
    public boolean isFull(){
        return usedSize==elem.length;
    }
    //出栈
    public int pop(){
        int val=0;
       try {
           isEmpty();
           val=elem[usedSize-1];
           usedSize--;

       }catch (EmptyException e){
           e.printStackTrace();
       }
        return val;
    }
    public void isEmpty(){
        if(usedSize==0){
            throw new EmptyException("空！！！");
        }
    }
      public int peek(){
          int val=0;
          try {
              isEmpty();
              val=elem[usedSize-1];
          }catch (EmptyException e){
              e.printStackTrace();
          }
          return val;
      }
}
